<?php
/**
 * 
 * ClientEngage: ClientEngage Visitor Voice (http://www.clientengage.com)
 * Copyright 2012, ClientEngage (http://www.clientengage.com)
 *
 * You must have purchased a valid license from CodeCanyon in order to have 
 * the permission to use this file.
 * 
 * You may only use this file according to the respective licensing terms 
 * you agreed to when purchasing this item on CodeCanyon.
 * 
 * 
 * 
 *
 * @author          ClientEngage <contact@clientengage.com>
 * @copyright       Copyright 2013, ClientEngage (http://www.clientengage.com)
 * @link            http://www.clientengage.com ClientEngage
 * @since           ClientEngage - Visitor Voice v 1.0
 * 
 */
?>
<div class="visitorforms view row">
    <div class="actions span3">

        <?php if ($visitorform['Visitorform']['visitorvoice_count'] > 0): ?>
            <ul class="nav nav-list">
                <li class="nav-header"><?php echo __('Responses'); ?></li>
                <li><?php echo $this->Html->link('<i class="ico-chart_curve"></i> ' . __('View Statistics'), array('controller' => 'visitorvoices', 'action' => 'statistics', $visitorform['Visitorform']['id']), array('class' => '', 'escape' => false)); ?></li>
                <li><?php echo $this->Html->link('<i class="ico-table"></i> ' . __('Response List'), array('controller' => 'visitorvoices', 'action' => 'responses', $visitorform['Visitorform']['id']), array('class' => '', 'escape' => false)); ?></li>
                <li><?php echo $this->Html->link('<i class="ico-page_white_excel"></i> ' . __('Export to Excel'), array('controller' => 'visitorvoices', 'action' => 'export', $visitorform['Visitorform']['id'], 'xls'), array('class' => '', 'escape' => false, 'target' => 'blank')); ?></li>
                <li><?php echo $this->Html->link('<i class="ico-page_white"></i> ' . __('Export to CSV'), array('controller' => 'visitorvoices', 'action' => 'export', $visitorform['Visitorform']['id'], 'csv'), array('class' => '', 'escape' => false, 'target' => 'blank')); ?></li>
            </ul>
            <hr />
        <?php endif; ?>

        <div class="row-fluid">
            <p class="nav-header"><?php echo __('Actions'); ?></p>
            <?php echo $this->Html->link(__('Edit Visitorform'), array('action' => 'edit', $visitorform['Visitorform']['id']), array('class' => 'btn span12')); ?> 
            <?php echo $this->Form->postLink(__('Duplicate Visitorform'), array('action' => 'duplicate', $visitorform['Visitorform']['id']), array('class' => 'btn blockinterface span12')); ?> 
            <?php echo $this->Form->postLink(__('Delete Visitorform'), array('action' => 'delete', $visitorform['Visitorform']['id']), array('class' => 'btn btn-danger span12'), __('Are you sure you want to delete "%s"?', $visitorform['Visitorform']['title'])); ?> 
        </div>

    </div>
    <div class="span9">
        <h2><?php echo __('Visitorform'); ?>  <small><?php echo $visitorform['Visitorform']['title']; ?></small></h2>
        <?php if ($visitorform['Visitorform']['visitorvoice_count'] > 0): ?>
            <div class="alert alert-block alert-error keepopen">
                <h4 class="alert-heading"><?php echo __('Form already active'); ?></h4>
                <p><?php echo __('This form has already been activated and contains responses. It is not advised to add new questions or remove or edit existing ones if you are unsure as to how this may affect your analysis results.'); ?></p>
            </div>
        <?php endif; ?>
        <dl>
            <dt><?php echo __('Title'); ?></dt>
            <dd>
                <?php echo h($visitorform['Visitorform']['title']); ?>
                &nbsp;
            </dd>
            <dt><?php echo __('Slug'); ?></dt>
            <dd>
                <code><?php echo $visitorform['Visitorform']['slug'] . ' ' . $this->Html->link('<i class="ico-link_go"></i>', array('controller' => 'visitorforms', 'action' => 'get', $visitorform['Visitorform']['slug'], 'admin' => false), array('target' => '_blank', 'escape' => false)); ?></code>
                &nbsp;
            </dd>
            <dt><?php echo __('Description'); ?></dt>
            <dd>
                <?php echo $visitorform['Visitorform']['description']; ?>
                &nbsp;
            </dd>
            <dt><?php echo __('Form Theme'); ?></dt>
            <dd>
                <?php echo $this->Html->link($visitorform['Formtheme']['title'], array('controller' => 'formthemes', 'action' => 'edit', $visitorform['Formtheme']['id'])); ?>
                &nbsp;
            </dd>
            <dt><?php echo __('Button Theme'); ?></dt>
            <dd>
                <?php echo $this->Html->link($visitorform['Buttontheme']['title'], array('controller' => 'buttonthemes', 'action' => 'edit', $visitorform['Buttontheme']['id'])); ?>
                &nbsp;
            </dd>
            <dt><?php echo __('Active'); ?></dt>
            <dd>
                <?php echo $this->Layout->boolYesNo($visitorform['Visitorform']['active']); ?>
                &nbsp;
            </dd>
            <dt><?php echo __('Visitorvoice Count'); ?></dt>
            <dd>
                <?php echo h($visitorform['Visitorform']['visitorvoice_count']); ?>
                &nbsp;
            </dd>
            <dt><?php echo __('Created'); ?></dt>
            <dd>
                <?php echo $this->Layout->displayTimeDefault($visitorform['Visitorform']['created']); ?>
                &nbsp;
            </dd>
            <dt><?php echo __('Modified'); ?></dt>
            <dd>
                <?php echo $this->Layout->displayTimeDefault($visitorform['Visitorform']['modified']); ?>
                &nbsp;
            </dd>
        </dl>
        <hr/>
        <?php
        $urlOut = rtrim(str_replace('https://', '', str_replace('http://', '', Router::url('/', true))), '/');

        $code = <<<CODE
<!-- VisitorVoice -->
<script type="text/javascript">
var _vvb = ('https:' == document.location.protocol ? 'https://' : 'http://') + '{$urlOut}';
var formId = '{$visitorform['Visitorform']['slug']}';

function loadVV() {
  var vvjs = document.createElement('script'); vvjs.type = 'text/javascript'; 
  vvjs.src = _vvb + '/code/'+ formId +'.js';   
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(vvjs, s);
};

if (window.addEventListener) window.addEventListener('load', loadVV, false); 
else if (window.attachEvent) window.attachEvent('onload', loadVV);
</script>
<!-- VisitorVoice -->   
CODE;
        ?>
        <div class="accordion" id="accordion2">
            <div class="accordion-group">
                <div class="accordion-heading">
                    <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseTwo">
                        <i class="ico-script_code"></i> <?php echo __('JavaScript Code'); ?>
                    </a>
                </div>
                <div id="collapseTwo" class="accordion-body collapse">
                    <div class="accordion-inner">
                        <?php echo '<pre>' . htmlentities($code) . '</pre>'; ?>
                        <?php echo '<span>' . __('Form Url:') . ' </span><code>' . Router::url(array('action' => 'get', $visitorform['Visitorform']['slug'], 'admin' => false), true) . '</code>'; ?>
                    </div>
                </div>
            </div>
        </div>
        <hr/>
        <?php foreach ($visitorform['Field'] as $field): ?>
            <div class="well">
                <div class="row-fluid">
                    <div class="span1">
                        <?php
                        echo '<span class="label">' . $field['position'] . '</span><br />';
                        echo $this->Html->link('<i class="ico-bullet_arrow_up"></i>', array('controller' => 'fields', 'action' => 'moveup', $field['id']), array('class' => 'bftn btfn-mini', 'escape' => false)) . '<br />';
                        echo $this->Html->link('<i class="ico-bullet_arrow_down"></i>', array('controller' => 'fields', 'action' => 'movedown', $field['id']), array('class' => 'btnf bftn-mini', 'escape' => false));
                        ?>
                    </div>
                    <div class="span11">
                        <div class="btn-group pull-right">
                            <?php
                            echo $this->Html->link(__('Edit'), array('controller' => 'fields', 'action' => 'editfield', $field['id']), array('class' => 'btn btn-mini btn_modal', 'escape' => false, 'data-field-id' => $field['id']));
                            echo $this->Form->postLink(__('Delete'), array('controller' => 'fields', 'action' => 'delete', $field['id']), array('class' => 'btn btn-danger btn-mini'), __('Are you sure you want to delete the field "%s"?', $field['title']));
                            ?>
                        </div>
                        <?php echo $this->Customform->renderField($field); ?>
                    </div>
                </div>
            </div>
        <?php endforeach; ?>
        <div class="row">
            <?php
            $fieldTypes = FieldType::getAll();
            ?>
            <div class="btn-group pull-right dropup">
                <a class="btn btn-large btn-primary dropdown-toggle" data-toggle="dropdown" href="#">
                    <?php echo __('Add Field'); ?>
                    <span class="caret"></span>
                </a>
                <ul class="dropdown-menu" style="max-height: 150px; overflow-y: scroll">
                    <?php
                    foreach ($fieldTypes as $name => $title)
                        if (!($name == FieldType::Captcha && Hash::check($visitorform, 'Field.{n}[type=captcha]')))
                            echo '<li>' . $this->Html->link($title, array('controller' => 'fields', 'action' => 'addfield', $visitorform['Visitorform']['id'], $name), array('class' => 'btn_modal')) . '</li>';
                    ?>
                </ul>
            </div>
        </div>


    </div>
</div>



